<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网上书城后台管理系统</title>
    <link rel="shortcut icon" href="../../favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css">
    <link rel="stylesheet" href="../../styles/login.css">
    <link rel="stylesheet" href="../../styles/icon/iconfont.css"/>
    <style>
        .body {
            min-width: 1366px;
        }
    </style>
</head>

<body>
<div class="login" id="login-app">
    <div class="login-box">
        <img src="../../images/login/login-bg.jpg" alt="">
        <div class="login-form">
            <el-form ref="loginForm">
                <div class="login-form-title">
                    <img src="../../images/login/logo.png" alt=""/>
                </div>
                <span style="color: red;">{{errorMsg}}</span>
                <el-form-item prop="username">
                    <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"
                              maxlength="20"
                              prefix-icon="iconfont icon-user"/>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input v-model="loginForm.password" type="password" placeholder="密码"
                              prefix-icon="iconfont icon-lock" maxlength="20"/>
                </el-form-item>
                <el-form-item style="width:100%;">
                    <el-button class="login-btn" size="medium" type="primary" style="width:100%;" @click="login">
                        登陆
                    </el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>

<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>

<script>
    new Vue({
        el: '#login-app',
        data() {
            return {
                loginForm: {
                    username: '',
                    password: ''
                },
                errorMsg: ''
            }
        },
        methods: {
            login() {
                let _this = this
                let data = new URLSearchParams();
                data.append('username', this.loginForm.username)
                data.append('password', this.loginForm.password)
                data.append('isAdmin', "1")
                axios({
                    method: 'post',
                    url: '/user/login',
                    data: data
                }).then((response) => {
                    if (response.data.success) {
                        window.localStorage.setItem('token', response.data.data)
                        location.href = '../../index.html';
                    } else {
                        _this.errorMsg = response.data.data
                    }
                })
            }
        }
    })
</script>
</body>

</html>
